package com.ch.web.mq;

import lombok.Data;

import java.io.Serializable;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;

@Data
public class MessageRegister implements Serializable,Comparable<MessageRegister> {
    private final static AtomicLong atomicLong = new AtomicLong(1);
    private static final long serialVersionUID = -1621937366995889958L;
    private Long id;
    private Boolean status;
    private Object data;
    private String routKey;

    public MessageRegister() {
    }


    public MessageRegister(String routKey, Object data) {
        this.id = atomicLong.getAndIncrement();
        this.data = data;
        this.routKey = routKey;
        this.status = false;
    }

    public static MessageRegister create(String routKey, Object data) {
        return new MessageRegister(routKey, data);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MessageRegister that = (MessageRegister) o;
        return Objects.equals(id, that.id) && Objects.equals(status, that.status) && Objects.equals(data, that.data) && Objects.equals(routKey, that.routKey);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, status, data, routKey);
    }

    @Override
    public int compareTo(MessageRegister o) {
        return Long.compare(this.getId(),o.getId());
    }

    public static AtomicLong getAtomicLong() {
        return atomicLong;
    }
}
